<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="java.io.Console"%>
<%@page import="java.util.logging.ConsoleHandler"%><html>
<%@ page import="utility.connections" %>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.CallableStatement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.SQLException"%>
<%@page import="oracle.jdbc.OracleTypes"%>
<script type="text/javascript" src="../js/immagini.js"></script>
<link href="../../layout.css" rel="stylesheet" type="text/css" media="screen" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Statistica n.1</title>
<style type="text/css">
<!--
.style1 {font-family: Verdana, Calibri, Cambria}
.style3 {font-family: Verdana, Calibri, Cambria; font-size: small; }
.style4 {
	font-family: Verdana, Calibri, Cambria;
	font-weight: bold;
	font-style: italic;
	color: #FFFFFF;
}
.style5 {font-size: small}
-->
</style>
</head>

<body>
<table width="700" height="422" border="0" align="center">
  <tr>
    <td align="center" valign="middle"></td>
  </tr>
  <tr>
    <td height="257" align="center" valign="top"><table width="100%" border="0">
      <tr>
        <td colspan="3" align="center"><div align="left">
          <p class="style3">
          
          <%  
		
			if (session.getAttribute("user")==null)
			response.sendRedirect("loginerr.jsp");
			
			else
			{
	
			String user = session.getAttribute("user").toString();
			String type = session.getAttribute("type").toString();
			String matr = session.getAttribute("matricola").toString();
			String nome = session.getAttribute("nome").toString();
			String cogn = session.getAttribute("cognome").toString();
			
			}
		%>
		
<%! String oracleUser = "azienda";
	String oraclePwd  = "azienda";
	Connection conn;
	String driver;
	String oracle;
	String user;
	String codice_b,legge,denominazione,importo; 
	Statement st;
%>
<%
	user = session.getAttribute("user").toString().toLowerCase();
	driver = "oracle.jdbc.driver.OracleDriver";
	oracle = "jdbc:oracle:thin:@localhost:1521:xe"; 
	
	try {
		Class.forName(driver);
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
	
	try {
		conn = DriverManager.getConnection(oracle, oracleUser, oraclePwd);
		st = conn.createStatement();
	} catch (SQLException e) {
		e.printStackTrace();
	}
%>
		  </p>
        </div></td>
        </tr>
      <tr>
        <td width="31%" class="style1"><p align="left">&nbsp;</p></td>
        <td width="48%" class="style1"><p align="center" class="style2">elecnco finanziamenti e importi </p></td>
        <td width="21%" class="style1">		</td>
      </tr>
      <tr>
        <td colspan="3" class="style1"><div align="center"><input type="button" value="INDIETRO" onclick="location.href='../hadm.jsp'"></input></div></td>
        </tr>
      <tr>
        <td colspan="3" class="style1"><table width="100%" cellpadding="2" cellspacing="0" bordercolor="#000000" style="border:1px solid;">
          <tr>
           <td width="8%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" >NUMERO</div></td>
            <td width="8%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" >CODICE BANDO</div></td>
            <td width="17%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" >LEGGE</div></td>
            <td width="21%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" >DENOMINAZIONE LEGGE</div></td>
            <td width="26%" bordercolor="#333333" bgcolor="#FFFF99" class="style3" style="border:1px solid;"><div align="center" >IMPORTO</div></td>
          </tr>

<%
				
	try {
	  	Connection conn = connections.getConnection();
	  	String callFunc = "begin ? := STAT1; end;";
	    CallableStatement callStmt = conn.prepareCall(callFunc);
	    callStmt.registerOutParameter(1, OracleTypes.CURSOR); 
	    callStmt.execute();
	    
	    ResultSet rs = (ResultSet)callStmt.getObject(1);
	    int i=0;
	    while (rs.next()) {
			       
			       //out.println(""+(i++)+" "+rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4)+" "+rs.getString(5)+" "+rs.getString(6)+"<BR>");
			        codice_b = rs.getString(1);
					legge = rs.getString(2);
					denominazione=rs.getString(3);
					importo=rs.getString(4);
					String color;
		            		String bordercell;
		            		
		            		i++;
		            		
		            		if (i%2==0)
		            		{
		            			color ="\"#E0E0E0\"";
		            			bordercell="style=\"border:1px solid;\";";
		            		}
		            		else
		            		{
		            			color = "\"#EFFFEF\"";
		            			bordercell="style=\"border:1px solid;\";";
		            		}
		            		
		            		out.println("<tr>");
		            		out.println("<td align=\"right\""+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + i + "</td>"); //prog.
		            		//out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ "><a href=\"modifica_stanza.jsp?codice="+codice+"&modify=0\">" + codice + "</a></td>");//
		            		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + codice_b + "</td>");
		            		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + legge + "</td>");
		            		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + denominazione + "</td>");
		            		out.println("<td "+bordercell+" bordercolor=\"#555555\" bgcolor = "+color+ ">" + importo + "</td>");
		            		out.println("</tr>");
	    }
		
		rs.close();
		
		callStmt.close();
		conn.close();
		
	  } catch ( SQLException ex ) {
	  	out.println(""+ex);
}
	//rs.close();
	//st.close();
	//conn.close();
%>
        </table></td>
        </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
